home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 34.zip / BS1 part 34 / FredFish PD 316.adf / SmartIcon / src / patch.c < prev    next >
C/C++ Source or Header  |  1990-02-06  |  4KB  |  166 lines

  1. #include <intuition/intuisup.h>
  2. #include <intuition/intuitionbase.h>
  3. #include "patch.h"
  4.  
  5.  
  6. extern USHORT GadgetsData[];
  7. extern struct WindowPatch   PList;
  8. extern struct IntuitionBase *IntuitionBase;
  9. extern struct MsgPort       *DefaultPort;
  10.  
  11. /* Global Read-Only data */
  12.  
  13. struct   Image    GadgetsImage = { -1,0, 50,10, 2, GadgetsData, 0x3,0x0, NULL };
  14. struct   Gadget   NewGadgets[NEWGADGETS] =
  15.    {
  16.       { NULL, -36,0, 15,10, GRELRIGHT, RELVERIFY, BOOLGADGET,
  17.         NULL, NULL, NULL, NULL, NULL, ICONGADGET, NULL },
  18.       { NULL, -19,0, 14,10, GRELRIGHT, RELVERIFY, SYSGADGET | WUPFRONT,
  19.         NULL, NULL, NULL, NULL, NULL, 0, NULL },
  20.       { NULL, -51,0, 14,10, GADGIMAGE | GRELRIGHT, RELVERIFY, SYSGADGET | WDOWNBACK,
  21.         (APTR)&GadgetsImage, NULL, NULL, NULL, NULL, 0, NULL },
  22.    };
  23.  
  24. struct WindowPatch
  25. *AddPatch()
  26. {
  27.    register struct WindowPatch *patch;
  28.  
  29.    if (patch = New(struct WindowPatch, 1))
  30.       {
  31.       patch->NextPatch = PList.NextPatch;
  32.       PList.NextPatch  = patch;
  33.       return(patch);
  34.       }
  35.    return(NULL);
  36. }
  37.  
  38. VOID
  39. RemovePatch(patch)
  40. register struct WindowPatch *patch;
  41. {
  42.    register struct WindowPatch *p = PList.NextPatch, *previous = NULL;
  43.  
  44. #ifdef DEBUG
  45. printf("removing patch [%s], ", patch->Window->Title);
  46. #endif
  47.  
  48.    while(p != patch) { previous = p; p = p->NextPatch; }
  49.  
  50.    if (previous) previous->NextPatch = patch->NextPatch;
  51.    else PList.NextPatch = patch->NextPatch;
  52.    CheckDelete(patch, 1);
  53. }
  54.  
  55. struct   WindowPatch
  56. *FindWPatch(window)
  57. register struct   Window   *window;
  58. {
  59.    register struct WindowPatch *p = PList.NextPatch;
  60.  
  61.    while (p)
  62.          {
  63.          if (p->Window == window) return(p);
  64.          p = p->NextPatch;
  65.          }
  66.    return(NULL);
  67. }
  68.  
  69. VOID
  70. UnPatchWindow(patch, refresh)
  71. register struct WindowPatch *patch;
  72. register BOOL   refresh;
  73. {
  74.    register struct Window  *w = patch->Window;
  75.  
  76. #ifdef DEBUG
  77. printf("unpatching window [%s]: ", w->Title);
  78. #endif
  79.    RemoveGList(w, patch->Gadgets, NEWGADGETS);
  80.  
  81.    if (patch->BackGadget && patch->FrontGadget)
  82.       {
  83. #ifdef DEBUG
  84. printf("restoring depth, ");
  85. #endif
  86.       AddGadget(w, patch->FrontGadget, 0);
  87.       if (refresh) RefreshGList(patch->FrontGadget, w, NULL, 1);
  88.       AddGadget(w, patch->BackGadget,  0);
  89.       if (refresh) RefreshGList(patch->BackGadget, w, NULL, 1);
  90.       }
  91.    if (w->UserPort==DefaultPort) w->UserPort = NULL;
  92.    RemovePatch(patch);
  93. #ifdef DEBUG
  94. printf("done\n");
  95. #endif
  96. }
  97.  
  98. VOID
  99. PatchWindow(window)
  100. register struct Window      *window;
  101. {
  102.    register USHORT i;
  103.    register struct Gadget        *g;
  104.    register struct WindowPatch   *patch = AddPatch();
  105.  
  106. #ifdef DEBUG
  107. printf("patching window [%s]: ", window->Title);
  108. #endif
  109.  
  110.    if (patch)
  111.       {
  112.       patch->Window = window;
  113.  
  114.       CopyMemQuick(NewGadgets, patch->Gadgets, NEWGADGETS*sizeof(struct Gadget));
  115.       for(i=0; i<NEWGADGETS; i++)
  116.          {
  117.          patch->Gadgets[i].NextGadget = &patch->Gadgets[i+1];
  118.          if (window->Flags & GIMMEZEROZERO) patch->Gadgets[i].GadgetType |= GZZGADGET;
  119.          }
  120.       patch->Gadgets[NEWGADGETS-1].NextGadget = NULL;
  121.  
  122.       for(g=window->FirstGadget; g; g=g->NextGadget)
  123.          {
  124.          if ((g->GadgetType & SYSGADGET) && (g->GadgetType &~GADGETTYPE)==WDOWNBACK) patch->BackGadget  = g;
  125.          if ((g->GadgetType & SYSGADGET) && (g->GadgetType &~GADGETTYPE)==WUPFRONT)  patch->FrontGadget = g;
  126.          }
  127.  
  128.       if (patch->BackGadget && patch->FrontGadget)
  129.          {
  130. #ifdef DEBUG
  131. printf("adding depth, ");
  132. #endif
  133.          RemoveGadget(window, patch->BackGadget);
  134.          RemoveGadget(window, patch->FrontGadget);
  135.  
  136.          AddGList(window, patch->Gadgets, 0, NEWGADGETS, NULL);
  137.          RefreshGList(patch->Gadgets, window, NULL, NEWGADGETS);
  138.  
  139.          /* This window has no port: let's give it one,  */
  140.          /* otherwise Intuition wont send msgs to it.    */
  141.          if (!window->UserPort) window->UserPort = DefaultPort;
  142.          /* Add GADGETUP/GADGETDOWN to the window IDCMPs */
  143.          /* trough our patched version of ModifyIDCMP(). */
  144.          ModifyIDCMP(window, window->IDCMPFlags);
  145.          }
  146.       }
  147. #ifdef DEBUG
  148. printf("done\n");
  149. #endif
  150. }
  151.  
  152. VOID
  153. PatchCurrentWindows()
  154. {
  155.    register struct   Screen   *screen = IntuitionBase->FirstScreen;
  156.    register struct   Window   *window;
  157.  
  158.    while (screen)
  159.          {
  160.          for(window=screen->FirstWindow; window; window=window->NextWindow) PatchWindow(window);
  161.          screen = screen->NextScreen;
  162.          }
  163. }
  164.  
  165.  
  166.